/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.site.ipodium.action;

import java.util.List;

import javax.inject.Inject;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.us.usws.common.SiteConstants;
import com.us.usws.model.domain.Meeting;
import com.us.usws.service.ro.MeetingROService;
import com.us.usws.site.ipodium.share.IpodiumPagination;
import com.us.usws.site.ipodium.share.Pagination;
import com.us.usws.support.uitls.SimpleDataPageUtil;
import com.us.usws.support.uitls.SiteWebContext;

/**
 * Struts2 action
 * @author robot
 */
public class MeetingAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private final int pageSize = 8;

	//private static Log log = LogFactory.getFactory().getInstance(EditProfileAction.class);

	@Inject
	MeetingROService roService;

	private int pageNo = 1;
	private List<Meeting> meetings;
	private int pageCnt;
	private int rowCount;

	private Pagination pg;

	/**
	 * load profile
	 * @return
	 */
	public String loadOnlineTrainingMeetings() {
		return getResult(SiteConstants.DSID_MEETING_TYPE_ONLINE_TRAINING, "/ipodium/listMeetingOnlineTraining.action");
	}

	public String loadMeetingWebClz() {
		return getResult(SiteConstants.DSID_MEETING_TYPE_WEB_CLZ, "/ipodium/listMeetingWebClz.action");
	}

	public String loadParentsMeeting() {
		return getResult(SiteConstants.DSID_MEETING_TYPE_PARENTS_MEETING, "/ipodium/listParentsMeeting.action");
	}

	public String loadParentsSurvey() {
		return getResult(SiteConstants.DSID_MEETING_TYPE_PARENTS_SURVEY, "/ipodium/listParentsSurvey.action");
	}

	/**
	 * get result
	 * @param meetingType
	 * @param listActionUrl
	 * @return
	 */
	private String getResult(int meetingType, String listActionUrl) {
		SiteWebContext swc = new SiteWebContext(ServletActionContext.getRequest(), ServletActionContext.getResponse());
		String uid = swc.getIpodiumUser().getUid();

		int rowCount = roService.getMeetingCountByPresenterAndType(uid, meetingType);
		SimpleDataPageUtil dpu = new SimpleDataPageUtil(pageSize, rowCount);
		dpu.setPageNo(pageNo);

		this.meetings = roService.getMeetingsByPresenterAndType(uid, meetingType, dpu.getStart(), pageSize);

		this.pageCnt = dpu.getPageCount();
		this.rowCount = rowCount;
		pg = new IpodiumPagination(pageNo, dpu.getPageCount(), listActionUrl);

		return SUCCESS;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageCnt() {
		return pageCnt;
	}

	public void setPageCnt(int pageCnt) {
		this.pageCnt = pageCnt;
	}

	public Pagination getPg() {
		return pg;
	}

	public void setPg(Pagination pg) {
		this.pg = pg;
	}

	public List<Meeting> getMeetings() {
		return meetings;
	}

	public void setMeetings(List<Meeting> meetings) {
		this.meetings = meetings;
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getPageSize() {
		return pageSize;
	}

}